Use case: Starting the GFXTIM with event generator ¶
This use case shows how to configure and start the event generator based on absolute line and relative frame events.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
GFXTIM_HandleTypeDef hgfxtim = {
.Instance = GFXTIM;
.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
};
/* GFXTIM initialization */
if (HAL_GFXTIM_Init(&hgfxtim) != HAL_OK);
/* optional: if interrupt is enabled */
/* Registering the user callback function*/
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_EVENT1_CB_ID,
USER_GFXTIM_EVENTGEN_EventCallback);
/* Clock generator configuration */
GFXTIM_ClockGeneratorConfigTypeDef pClockGeneratorConfig = {
.LCCClockSrc = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
.LCCHwReloadSrc = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
.LCCReloadValue = 159999;
.LineClockSrc = GFXTIM_LINE_CLK_SRC_HSYNC_FALLING;
.FCCReloadValue = 1;
.FCCHwReloadSrc = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCClockSrc = GFXTIM_FCC_CLK_SRC_HSYNC_RISING;
.FrameClockSrc = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
.LineClockCalib = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
&pClockGeneratorConfig);
/* Absolute line configuration */
GFXTIM_AbsoluteTimerConfigTypeDef pAbsoluteTimerConfig = {
.LineCompare1Value = 1;
.LineCompare2Value = 3;
.LineCounterValue = 0;
.LineOverflowInterrupt = DISABLE;
.LineCompare1Interrupt = DISABLE;
.LineCompare2Interrupt = DISABLE;
};
HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim,
&pAbsoluteTimerConfig);
/* Relative frame configuration */
GFXTIM_RelativeTimerConfigTypeDef RTimConfig = {
.AutoReloadValue = 200;
.CounterMode = GFXTIM_MODE_CONTINUOUS;
.ReloadInterrupt = GFXTIM_IT_DISABLE;
};
HAL_GFXTIM_RelativeTimer_Config(&hgfxtim,
&RTimConfig,
GFXTIM_RELATIVE_TIMER1);
/* Event generator configuration */
GFXTIM_EventGeneratorConfigTypeDef EventConfig = {
.FrameEvent = GFXTIM_FRAME_EVENT_RFC1_RELOAD;
.LineEvent = GFXTIM_LINE_EVENT_ALC1_COMPARE;
.EventInterrupt = GFXTIM_IT_ENABLE;
};
HAL_GFXTIM_EventGenerator_Config(&hgfxtim,
GFXTIM_EVENT_GENERATOR_1,
&EventConfig);
/* Start absolute line */
HAL_GFXTIM_AbsoluteTimer_Start(&hgfxtim);
/* Start relative frame */
HAL_GFXTIM_RelativeTimer_Start(&hgfxtim,
GFXTIM_RELATIVE_TIMER1);
/* Enable the event generator */
HAL_GFXTIM_EventGenerator_Enable(&hgfxtim,
GFXTIM_EVENT_GENERATOR_1);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_EventGenerator_EV1Callback(&hgfxtim);
/* optional */
/* Stop the event generator 1 */
HAL_GFXTIM_EventGenerator_Disable(&hgfxtim,
GFXTIM_EVENT_GENERATOR_1);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
hal_gfxtim_handle_t hgfxtim;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function*/
HAL_GFXTIM_EVENTGEN_RegisterEventCallback(&hgfxtim,
USER_GFXTIM_EVENTGEN_EventCallback);
/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_line_config_t p_line_config = {
.counter_src = HAL_GFXTIM_CLKGEN_LINE_COUNT_NONE;
.reload_src = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
.reload_val = 159999;
.clock_src = HAL_GFXTIM_CLKGEN_LINE_HSYNC_FALLING;
};
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val = 1;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_HSYNC_RISING;
.clock_src = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};
HAL_GFXTIM_CLKGEN_SetConfigLineFrameClock(&hgfxtim,
&p_frame_config,
&p_line_config);
/* Absolute line configuration */
HAL_GFXTIM_ABSTIM_SetLineCounter(&hgfxtim,0x0U);
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COMP_1,
1U);
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COMP_2,
3U);
/* Configure the event generator */
hal_gfxtim_eventgen_config_t p_config = {
.line_event = HAL_GFXTIM_EVENTGEN_ABS_LCNT_1_COMP;
.frame_event = HAL_GFXTIM_EVENTGEN_REL_FCNT_1_RELOAD;
};
HAL_GFXTIM_EVENTGEN_SetConfig(&hgfxtim,
HAL_GFXTIM_EVENTGEN_EVENT_1,
&p_config);
/* Start the absolute frame counter */
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COUNTER,
HAL_GFXTIM_NONE_IT);
/* Start the relative frame counter in continuous mode */
HAL_GFXTIM_RELTIM_StartContinuous(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1,
200U,
HAL_GFXTIM_RELTIM_COUNT_IT);
/* Start the event generator */
HAL_GFXTIM_EVENTGEN_Start(&hgfxtim,
HAL_GFXTIM_EVENTGEN_EVENT_1,
HAL_GFXTIM_EVENTGEN_EVENT_IT);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_EVENTGEN_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_EVENTGEN_EventCallback(&hgfxtim,
HAL_GFXTIM_EVENTGEN_EVENT_1);
/* optional */
/* Stop the event generator 1 */
HAL_GFXTIM_EVENTGEN_Stop(&hgfxtim,
GFXTIM_EVENTGEN_Event_1);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
Key changes ¶
HAL2 configures and starts the event generator through dedicated EVENTGEN APIs.
HAL2 relies on the HAL2 absolute and relative timer APIs for the line and frame event sources.

